<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>系统任务配置</title>
    <link rel="stylesheet" href="<?=adminassets?>assets/pear/component/pear/css/pear.css" />
    <link rel="stylesheet" href="<?=adminassets?>assets/css/cron.css" />
</head>

<body class="pear-container">
    <!-- 配置卡片 -->
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <i class="layui-icon layui-icon-set"></i>
                    系统配置
                </div>
                <div class="layui-card-body">
                    <form onsubmit="return saveSetting(this)" method="post" role="form">
                        <div class="layui-row layui-col-space15">
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">计划任务密钥</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="cronkey" value="<?=$this->conf['cronkey']?>" 
                                            class="layui-input" lay-verify="required" placeholder="请输入计划任务访问密钥">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md6">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">微信白名单IP</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="wxip" value="<?=$this->conf['wxip']?>" 
                                            class="layui-input" placeholder="多个IP使用|分隔">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="submit" class="pear-btn pear-btn-primary">
                                    <i class="layui-icon layui-icon-ok"></i>
                                    更新配置
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- 任务列表卡片 -->
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <i class="layui-icon layui-icon-time"></i>
                    计划任务列表
                </div>
                <div class="layui-card-body">
                    <div class="layui-collapse" lay-accordion>
                        <!-- 订单刷新监控 -->
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">订单刷新监控 <span class="layui-badge layui-bg-green">推荐周期: 1秒</span></h2>
                            <div class="layui-colla-content layui-show">
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 0; position: relative;">
                                        <input type="text" value="<?=$this->httphost?>Cron/sxorder/<?=$this->conf['cronkey']?>" 
                                            class="layui-input" readonly style="padding-right: 95px;">
                                        <button type="button" class="copy-btn" style="position: absolute; right: 8px; top: 8px; 
                                            background: transparent; border: none; padding: 6px 15px; cursor: pointer; color: #5FB878; font-size: 14px;
                                            z-index: 1;"
                                            data-clipboard-text="<?=$this->httphost?>Cron/sxorder/<?=$this->conf['cronkey']?>">
                                            <i class="layui-icon layui-icon-file"></i> 复制
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 微信云端监控 -->
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">微信云端监控 <span class="layui-badge layui-bg-green">推荐周期: 1-10秒</span></h2>
                            <div class="layui-colla-content">
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 0; position: relative;">
                                        <input type="text" value="<?=$this->httphost?>Cron/wxyun/<?=$this->conf['cronkey']?>" 
                                            class="layui-input" readonly style="padding-right: 95px;">
                                        <button type="button" class="copy-btn" style="position: absolute; right: 8px; top: 8px; 
                                            background: transparent; border: none; padding: 6px 15px; cursor: pointer; color: #5FB878; font-size: 14px;
                                            z-index: 1;"
                                            data-clipboard-text="<?=$this->httphost?>Cron/wxyun/<?=$this->conf['cronkey']?>">
                                            <i class="layui-icon layui-icon-file"></i> 复制
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- MAPI辅助监控 -->
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">MAPI辅助监控 <span class="layui-badge layui-bg-green">推荐周期: 1秒</span></h2>
                            <div class="layui-colla-content">
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 0; position: relative;">
                                        <input type="text" value="<?=$this->httphost?>Cron/MapiNotify/<?=$this->conf['cronkey']?>" 
                                            class="layui-input" readonly style="padding-right: 95px;">
                                        <button type="button" class="copy-btn" style="position: absolute; right: 8px; top: 8px; 
                                            background: transparent; border: none; padding: 6px 15px; cursor: pointer; color: #5FB878; font-size: 14px;
                                            z-index: 1;"
                                            data-clipboard-text="<?=$this->httphost?>Cron/Notify/<?=$this->conf['cronkey']?>">
                                            <i class="layui-icon layui-icon-file"></i> 复制
                                        </button>
                                        <div class="layui-word-aux" style="padding-top: 5px; padding-bottom: 5px;">
                                            <span class="layui-badge-dot layui-bg-orange"></span>
                                            使用MAPI可以解决部分收款码不回调的问题，但不保证完全解决。不需要时请勿开启，以免影响服务器性能。
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 店员辅助监控 -->
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">店员辅助监控 <span class="layui-badge layui-bg-green">推荐周期: 15秒</span></h2>
                            <div class="layui-colla-content">
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 0; position: relative;">
                                        <input type="text" value="<?=$this->httphost?>Cron/wx_dytime/<?=$this->conf['cronkey']?>" 
                                            class="layui-input" readonly style="padding-right: 95px;">
                                        <button type="button" class="copy-btn" style="position: absolute; right: 8px; top: 8px; 
                                            background: transparent; border: none; padding: 6px 15px; cursor: pointer; color: #5FB878; font-size: 14px;
                                            z-index: 1;"
                                            data-clipboard-text="<?=$this->httphost?>Cron/wx_dytime/<?=$this->conf['cronkey']?>">
                                            <i class="layui-icon layui-icon-file"></i> 复制
                                        </button>
                                        <div class="layui-word-aux" style="padding-top: 5px; padding-bottom: 5px;">
                                            <span class="layui-badge-dot layui-bg-orange"></span>
                                            店员在线后会自动更新
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 支付宝QQ更新CK -->
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">支付宝QQ更新CK <span class="layui-badge layui-bg-green">推荐周期: 1-5秒</span></h2>
                            <div class="layui-colla-content">
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 0; position: relative;">
                                        <input type="text" value="<?=$this->httphost?>Cron/aliqqyun/<?=$this->conf['cronkey']?>" 
                                            class="layui-input" readonly style="padding-right: 95px;">
                                        <button type="button" class="copy-btn" style="position: absolute; right: 8px; top: 8px; 
                                            background: transparent; border: none; padding: 6px 15px; cursor: pointer; color: #5FB878; font-size: 14px;
                                            z-index: 1;"
                                            data-clipboard-text="<?=$this->httphost?>Cron/aliqqyun/<?=$this->conf['cronkey']?>">
                                            <i class="layui-icon layui-icon-file"></i> 复制
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 检测所有二维码风控 -->
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">检测所有二维码风控 <span class="layui-badge layui-bg-green">推荐周期: 1分钟</span></h2>
                            <div class="layui-colla-content">
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 0; position: relative;">
                                        <input type="text" value="<?=$this->httphost?>Cron/fkjk/<?=$this->conf['cronkey']?>" 
                                            class="layui-input" readonly style="padding-right: 95px;">
                                        <button type="button" class="copy-btn" style="position: absolute; right: 8px; top: 8px; 
                                            background: transparent; border: none; padding: 6px 15px; cursor: pointer; color: #5FB878; font-size: 14px;
                                            z-index: 1;"
                                            data-clipboard-text="<?=$this->httphost?>Cron/fkjk/<?=$this->conf['cronkey']?>">
                                            <i class="layui-icon layui-icon-file"></i> 复制
                                        </button>
                                        <div class="layui-word-aux" style="padding-top: 5px; padding-bottom: 5px;">
                                            <span class="layui-badge-dot layui-bg-orange"></span>
                                            此计划任务需要在用户中心开启，才会生效
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 清理所有未支付订单 -->
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">清理所有未支付订单 <span class="layui-badge layui-bg-green">推荐周期: 1分钟</span></h2>
                            <div class="layui-colla-content">
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 0; position: relative;">
                                        <input type="text" value="<?=$this->httphost?>Cron/qlwzf/<?=$this->conf['cronkey']?>" 
                                            class="layui-input" readonly style="padding-right: 95px;">
                                        <button type="button" class="copy-btn" style="position: absolute; right: 8px; top: 8px; 
                                            background: transparent; border: none; padding: 6px 15px; cursor: pointer; color: #5FB878; font-size: 14px;
                                            z-index: 1;"
                                            data-clipboard-text="<?=$this->httphost?>Cron/qlwzf/<?=$this->conf['cronkey']?>">
                                            <i class="layui-icon layui-icon-file"></i> 复制
                                        </button>
                                        <div class="layui-word-aux" style="padding-top: 5px; padding-bottom: 5px;">
                                            <span class="layui-badge-dot layui-bg-orange"></span>
                                            此计划任务每次清理最大100条
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


                        <!-- 会员过期提醒 -->
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">会员过期提醒 <span class="layui-badge layui-bg-green">推荐周期: 1分钟</span></h2>
                            <div class="layui-colla-content">
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 0; position: relative;">
                                        <input type="text" value="<?=$this->httphost?>Cron/user_vips/<?=$this->conf['cronkey']?>" 
                                            class="layui-input" readonly style="padding-right: 95px;">
                                        <button type="button" class="copy-btn" style="position: absolute; right: 8px; top: 8px; 
                                            background: transparent; border: none; padding: 6px 15px; cursor: pointer; color: #5FB878; font-size: 14px;
                                            z-index: 1;"
                                            data-clipboard-text="<?=$this->httphost?>Cron/user_vips/<?=$this->conf['cronkey']?>">
                                            <i class="layui-icon layui-icon-file"></i> 复制
                                        </button>
                                        <div class="layui-word-aux" style="padding-top: 5px; padding-bottom: 5px;">
                                            <span class="layui-badge-dot layui-bg-orange"></span>
                                            需要在用户中心开启
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- APP掉线检测 -->
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">APP掉线检测 <span class="layui-badge layui-bg-green">推荐周期: 5-10秒</span></h2>
                            <div class="layui-colla-content">
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 0; position: relative;">
                                        <input type="text" value="<?=$this->httphost?>Cron/appcron/<?=$this->conf['cronkey']?>" 
                                            class="layui-input" readonly style="padding-right: 95px;">
                                        <button type="button" class="copy-btn" style="position: absolute; right: 8px; top: 8px; 
                                            background: transparent; border: none; padding: 6px 15px; cursor: pointer; color: #5FB878; font-size: 14px;
                                            z-index: 1;"
                                            data-clipboard-text="<?=$this->httphost?>Cron/appcron/<?=$this->conf['cronkey']?>">
                                            <i class="layui-icon layui-icon-file"></i> 复制
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Shell脚本示例 -->
                    <div class="layui-card" style="margin-top: 15px;">
                        <div class="layui-card-header">
                            <i class="layui-icon layui-icon-code-circle"></i>
                            通用Shell脚本
                        </div>
                        <div class="layui-card-body">
                            <blockquote class="layui-elem-quote layui-quote-nm">
                                宝塔"计划任务"监控步骤：计划任务->Shell脚本->执行周期设为"1分钟"->脚本内容如下
                            </blockquote>
                            <pre class="layui-code" lay-title="Shell脚本" lay-skin="notepad">
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
step=1 #设置1秒的监控速度
for (( i = 0; i < 60; i=(i+step) )); do
    curl -sS --connect-timeout 10 -m 60 '任务链接'
    endDate=`date +"%Y-%m-%d %H:%M:%S"`
    echo "★[$endDate] Successful"
    sleep $step
done
exit 0
                            </pre>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="<?=adminassets?>assets/pear/component/layui/layui.js"></script>
    <script src="<?=adminassets?>assets/pear/component/pear/pear.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.8/clipboard.min.js"></script>
    <script src="<?=adminassets?>assets/js/core_js/set.js"></script>
    <script>
        layui.use(['form', 'element', 'code', 'layer'], function() {
            var form = layui.form;
            var element = layui.element;
            var layer = layui.layer;
            
            // 初始化代码高亮
            layui.code({
                about: false
            });

            // 初始化复制功能
            var clipboard = new ClipboardJS('.copy-btn');
            clipboard.on('success', function(e) {
                var btn = e.trigger;
                var originalText = btn.innerHTML;
                btn.innerHTML = '<i class="layui-icon layui-icon-ok"></i> 已复制';
                btn.style.color = '#009688';
                setTimeout(function() {
                    btn.innerHTML = originalText;
                    btn.style.color = '#5FB878';
                }, 1500);
                e.clearSelection();
            });
            
            // 添加hover效果
            document.querySelectorAll('.copy-btn').forEach(function(btn) {
                btn.addEventListener('mouseover', function() {
                    this.style.color = '#009688';
                });
                btn.addEventListener('mouseout', function() {
                    this.style.color = '#5FB878';
                });
            });
        });
    </script>
</body>
</html>